<?php
#开发者中心回去的API Key 和 Secret Key
$RENREN_APP_API_KEY = "999e434112b5482c83b608a54a1848b3";
$RENREN_APP_SECRET_KEY = "ce4a7b6180bd466ba0e2b6d8ef8075a2 ";

#获取Authorization Code 的URI
$RENREN_AUTHORIZATION_URI = "https://graph.renren.com/oauth/authorize";

#获取Access Token 的URI
$RENREN_ACCESS_TOKEN_URI = "https://graph.renren.com/oauth/token";

#人人API Session Key 资源URI
$RENREN_SESSION_KEY_URI = "https://graph.renren.com/renren_api/session_key";

#人人API Server URI
$RENREN_API_SERVER = "https://api.renren.com/restserver.do";
var_dump($_GET);
$authorization_code = $_GET['code'];

var_dump($authorization_code);

#设置请求参数，包括：client_id、client_secret、redirect_uri、code、和grant_type
$snoopy = new Snoopy();
$snoopy->fetch($RENREN_ACCESS_TOKEN_URI."?client_id=".$RENREN_APP_API_KEY."&redirect_uri=http://lapula.com:89/free/test2.php&client_secret=".$RENREN_APP_SECRET_KEY."&code=".$authorization_code."&grant_type=authorization_code");

#发送请求到获取Access Token URI
$response = $snoopy->results;
var_dump($response);

#解析返回JSON中“access_token”
$ret = json_decode($response);
var_dump($ret);
$access_token = $ret["access_token"];
var_dump($access_token);

#发送请求到资源服务器，并带上已经获取的Access Token
$response = $snoopy->fetch($RENREN_SESSION_KEY_URI + "?oauth_token=".$access_token);
$ret = json_decode($response);
var_dump($ret);

$session_key = $ret["renren_token"]["session_key"];
var_dump($session_key);


